
package com.slink.fxfk.framework.util;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 新
 *
 */
public class SessionUtil {
	
	public static final String MEM_SESSION_INFO = "mem_session_info";

	public static final String LOGIN_VERIFY_CODE = "login_verify_code";

	private SessionUtil() {
	}

	/**
	 * 获取会员标识
	 * 
	 * @param request
	 * @return
	 */
	public static String getMemberId(HttpServletRequest request) {
		Object Object = (Object) request.getSession()
				.getAttribute(MEM_SESSION_INFO);
		return Object.toString();
	}

	/**
	 * 设置会员session信息
	 * 
	 * @param request
	 * @param bMember
	 */
	public static void setMemberSession(HttpServletRequest request,
			Object Object) {
		request.getSession().setAttribute(MEM_SESSION_INFO, Object);
	}

	/**
	 * 清空session信息
	 * 
	 * @param request
	 */
	public static void clearSession(HttpServletRequest request) {

		request.getSession().removeAttribute(MEM_SESSION_INFO);
	}

	/**
	 * 获取会员session信息
	 * 
	 * @param request
	 * @return
	 */
	public static Object getMemberSession(HttpServletRequest request) {
		Object Object = (Object) request.getSession()
				.getAttribute(MEM_SESSION_INFO);

		return Object;
	}

	/**
	 * 获取网站访问根路径
	 * 
	 * @param request
	 * @return
	 */
	public static String getSiteRoot(HttpServletRequest request) {
		String path = request.getContextPath();
		String basePath = request.getScheme()
				+ "://"
				+ request.getServerName()
				+ (request.getServerPort() == 80 ? "" : ":"
						+ request.getServerPort()) + path;
		return basePath;
	}

	/**
	 * 设置登录验证码
	 * 
	 * @param request
	 * @param verifyCode
	 */
	public static void setLoginVerifyCode(HttpServletRequest request,
			String verifyCode) {
		request.getSession().setAttribute(LOGIN_VERIFY_CODE, verifyCode);
	}

	/**
	 * 获取登录验证码
	 * 
	 * @param request
	 * @return
	 */
	public static String getloginVerifyCode(HttpServletRequest request) {
		return (String) request.getSession().getAttribute(LOGIN_VERIFY_CODE);
	}
}
